//
//  JCStatusPhotoImageView.swift
//  SinaWeibo_18
//
//  Created by apple on 15/10/21.
//  Copyright © 2015年 cz. All rights reserved.
//

import UIKit

class JCStatusPhotoImageView: UIImageView {
    
   private var giftImageView: UIImageView?

    var thumbnail_pic: String?{
        didSet{
        
            //判断是否是gif图片
            if let picUrl = thumbnail_pic{
                sd_setImageWithURL(NSURL(string: picUrl), placeholderImage: UIImage(named: "timeline_image_placeholder"))
                //隐藏
//                giftImageView?.hidden = !picUrl.hasPrefix(".gif")
                if picUrl.hasSuffix(".gif") {
                    giftImageView?.hidden = false
                }else{
                    giftImageView?.hidden = true
                }
            }
        }
    }
    
   override init(frame: CGRect) {
        super.init(frame: frame)
    
    //图片宽高比 填充
    contentMode = UIViewContentMode.ScaleAspectFill
    clipsToBounds = true
    //添加gif图片
    let gifImageView = UIImageView(image: UIImage(named: "timeline_image_gif"))
    self.giftImageView = gifImageView
    addSubview(gifImageView)
    
    }

   required init?(coder aDecoder: NSCoder) {
       fatalError("init(coder:) has not been implemented")
   }
    
    override func layoutSubviews() {
        super.layoutSubviews()
    
        //设置gif图片位置
        self.giftImageView!.x = width - self.giftImageView!.width
        self.giftImageView!.y = height - self.giftImageView!.height
        
    }

}
